package Pattern.Observer.weather.Observer;

import Pattern.Observer.weather.Subject.Subject;

/**
 * 观察者之一
 */
public class CurrentConditionsDisplay implements Observer,DisplayElement {
    private float temperature;
    private float humidity;
    //Subject声明为成员变量是为了方便注册和取消注册
    private Subject weratherData;

    /**
     *
     * @param weratherData 被观察的对象（主题）
     */
    public CurrentConditionsDisplay(Subject weratherData) {
        this.weratherData = weratherData;
        weratherData.registerObserver(this);
    }

    @Override
    public void display() {
        System.out.println("Current conditions: "+temperature+"F degrees and "+humidity+"% humidity");
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature=temp;
        this.humidity=humidity;
        display();
    }
}
